package cn.com.egova.web.action;

import cn.com.egova.domain.Dict;
import cn.com.egova.service.DictService;
import cn.com.egova.utils.FastJsonUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by yuanchao on 2020/5/24.
 */
public class DictAction extends ActionSupport implements ModelDriven<Dict> {
    private static final long serialVersionUID = 32498435346349l;
    private DictService dictService;
    private Dict dict = new Dict();

    public void setDictService(DictService dictService) {
        this.dictService = dictService;
    }

    public String findByCode(){
        List<Dict> list = dictService.findByCode(dict.getDict_type_code());
        HttpServletResponse response = ServletActionContext.getResponse();
        String jsonString = FastJsonUtil.toJSONString(list);
        FastJsonUtil.writeJson(response, jsonString);
        return NONE;
    }

    @Override
    public Dict getModel() {
        return dict;
    }
}
